import com.itheima.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class UserApp {
    public static void main(String[] args) {
        // 2. 加载配置文件
//        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
//        // 3. 获取资源
//        UserService userService1 = (UserService) applicationContext.getBean("userService3");
//        UserService userService2 = (UserService) applicationContext.getBean("userService3");
//        UserService userService3 = (UserService) applicationContext.getBean("userService3");
//        System.out.println(userService1);
//        System.out.println(userService2);
//        System.out.println(userService3);
//        System.out.println("userService1和userService2是不是同一个对象："+(userService1 == userService2));

//        userService.save();

//        ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
//        UserService userService1 = (UserService)applicationContext.getBean("userService3");
//        UserService userService2 = (UserService)applicationContext.getBean("userService3");
//        UserService userService3 = (UserService)applicationContext.getBean("userService3");
//        applicationContext.close();

//        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
//        UserService userService = (UserService) applicationContext.getBean("userService5");
//        userService.save();

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        UserService userService = (UserService) applicationContext.getBean("userService");
        userService.save();
    }
}
